﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Graffiti.Core;

namespace GraffitiExtras.Extensions.ShareThis
{

    /// <summary>
    /// ShareThis STAPI (http://sharethis.com)
    /// </summary>
    [Chalk("shareThis")]
    public class ShareThis
    {
        public string Write(Post post)
        {
            return Write(post,"Share me");
        }

        public string Write(Post post,string title)
        {
            var sb = new StringBuilder();

            sb.AppendLine("<script language=\"javascript\" type=\"text/javascript\">");
            sb.AppendLine("SHARETHIS.addEntry({");
            sb.AppendFormat("title:'{0}',",title);
            sb.AppendFormat("url: 'http://{0}{1}{2}'", HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.ApplicationPath, post.Url);
            sb.AppendLine("}, {button:true} );");
            sb.AppendLine("</script>");

            return sb.ToString();
        }
    }
}
